﻿using System;
using System.Data;

namespace Library.OrmEnterpriseEntity.TableInfo {
	///<summary>
	///</summary>
	public class DoubleColumn : Column<Double>, IConvertible {
		///<summary>
		///</summary>
		///<param name="metadata"></param>
		///<param name="table"></param>
		public DoubleColumn(DbColumnView metadata, DbTable table)
			: base(metadata, table) {
		}
		public override string ToString(string format, IFormatProvider formatProvider) {
			return Value.ToString(format, formatProvider);
		}
		///<summary>
		///</summary>
		///<param name="value"></param>
		///<returns></returns>
		public static implicit operator DoubleColumn(double value) {
			return new DoubleColumn(DoubleColumnView.Null, DbTable.Null) { Value = value };
		}
		///<summary>
		///</summary>
		public const Double DefaultDouble = 0;

		protected override double Default {
			get { return DefaultDouble; }
		}

		public TypeCode GetTypeCode() {
			return TypeCode.Double;
		}

		public bool ToBoolean(IFormatProvider provider) {
			return ((IConvertible)Value).ToBoolean(provider);
		}

		public char ToChar(IFormatProvider provider) {
			return ((IConvertible)Value).ToChar(provider);
		}

		public sbyte ToSByte(IFormatProvider provider) {
			return ((IConvertible)Value).ToSByte(provider);
		}

		public byte ToByte(IFormatProvider provider) {
			return ((IConvertible)Value).ToByte(provider);
		}

		public short ToInt16(IFormatProvider provider) {
			return ((IConvertible)Value).ToInt16(provider);
		}

		public ushort ToUInt16(IFormatProvider provider) {
			return ((IConvertible)Value).ToUInt16(provider);
		}

		public int ToInt32(IFormatProvider provider) {
			return ((IConvertible)Value).ToInt32(provider);
		}

		public uint ToUInt32(IFormatProvider provider) {
			return ((IConvertible)Value).ToUInt32(provider);
		}

		public long ToInt64(IFormatProvider provider) {
			return ((IConvertible)Value).ToInt64(provider);
		}

		public ulong ToUInt64(IFormatProvider provider) {
			return ((IConvertible)Value).ToUInt64(provider);
		}

		public float ToSingle(IFormatProvider provider) {
			return ((IConvertible)Value).ToSingle(provider);
		}

		public double ToDouble(IFormatProvider provider) {
			return ((IConvertible)Value).ToDouble(provider);
		}

		public decimal ToDecimal(IFormatProvider provider) {
			return ((IConvertible)Value).ToDecimal(provider);
		}

		public DateTime ToDateTime(IFormatProvider provider) {
			return ((IConvertible)Value).ToDateTime(provider);
		}

		public string ToString(IFormatProvider provider) {
			return ((IConvertible)Value).ToString(provider);
		}

		public object ToType(Type conversionType, IFormatProvider provider) {
			return ((IConvertible)Value).ToType(conversionType, provider);
		}

		//public override DbType DbType {
		//  get { return DbType.Double; }
		//}

		protected override double ConvertFrom(object value) {
			return Convert.ToDouble(value);
		}

		protected override bool Equal(double t1, double t2) {
			return t2 == t1;
		}
	}
}
